package org.store.domain;

import java.util.HashMap;
import java.util.Map;

public class Order extends Identified {
    private final Map<Product, Integer> products = new HashMap<Product, Integer>();
    private final Payment payment;
    private final Buyer buyer;
    private final Long sum;

    public Order(Payment payment, Buyer buyer, Long sum) {
        this.payment = payment;
        this.buyer = buyer;
        this.sum = sum;
    }

    public Map<Product, Integer> getProducts() {
        return products;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Order)) return false;
        if (!super.equals(o)) return false;

        Order order = (Order) o;

        if (buyer != null ? !buyer.equals(order.buyer) : order.buyer != null) return false;
        if (payment != null ? !payment.equals(order.payment) : order.payment != null) return false;
        if (products != null ? !products.equals(order.products) : order.products != null) return false;
        if (sum != null ? !sum.equals(order.sum) : order.sum != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (products != null ? products.hashCode() : 0);
        result = 31 * result + (payment != null ? payment.hashCode() : 0);
        result = 31 * result + (buyer != null ? buyer.hashCode() : 0);
        result = 31 * result + (sum != null ? sum.hashCode() : 0);
        return result;
    }

    public Payment getPayment() {
        return payment;
    }

    public Buyer getBuyer() {
        return buyer;
    }

    public Long getSum() {
        return sum;
    }
}
